package com.yuyou.tas.report.controller;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

import com.yuyou.tas.util.exception.CheckException;

@ApiIgnore
@RestController
@RequestMapping(value="/health")
public class CheckController {

   
	@Autowired
	private StringRedisTemplate stringRedisTemplate;

    @RequestMapping(value ="/ready",method = {RequestMethod.GET, RequestMethod.POST})
    public String ready(){
    	try{
        	//1.redis
        	stringRedisTemplate.opsForValue().set("ready", "1", 1,TimeUnit.SECONDS);
        	//2.mysql
    	}catch(Exception e){
    		throw new CheckException("ready error");
    	}  	
    	return "ok";
    }	
	
    @RequestMapping(value ="/alive",method = {RequestMethod.GET, RequestMethod.POST})
    public String alive(){
    	try{
        	//1.redis
        	stringRedisTemplate.opsForValue().set("ready", "1", 1,TimeUnit.SECONDS);
        	//2.mysql
    	}catch(Exception e){
    		throw new CheckException("ready error");
    	}  	
    	return "ok";
    }	

	
	
}
